
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Text;
using Ezio.Model;
using System.Collections;

//Service Route: Copy to 'Global.asax'
//  RouteTable.Routes.Add(new ServiceRoute("Colegios", new WebServiceHostFactory(), typeof(ColegiosService)));
//
namespace Ezio.Service
{
    [ServiceContract]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
    [XmlSerializerFormat]
    public class ColegiosService : BaseService
    {
        [WebInvoke(UriTemplate = "Create", Method = "POST")]
        public bool Create(Colegios Colegio)
        {
            Provider.AddToColegios(Colegio);
            return Provider.TrySaveChanges();

        }

        [WebInvoke(UriTemplate = "GetAll", Method = "POST")]
        public ArrayList GetAll()
        {
            return new ArrayList(Provider.Colegios.ToList());
        }

        [WebInvoke(UriTemplate = "GetById", Method = "POST")]
        public Colegios GetById(int Id)
        {
            return Provider.Colegios.First(i => i.IdColegio == Id);
        }

        [WebInvoke(UriTemplate = "Update", Method = "POST")]
        public bool Update(Colegios Colegio)
        {
            Colegios miColegio = Provider.Colegios.Where(t => t.IdColegio == Colegio.IdColegio).First();
            miColegio.Copy(Colegio);
            return Provider.TrySaveChanges();
        }

        [WebInvoke(UriTemplate = "Delete", Method = "POST")]
        public bool Delete(int IdColegio)
        {
            Provider.Colegios.DeleteObject(Provider.Colegios.Where(t => t.IdColegio == IdColegio).First());
            return Provider.TrySaveChanges();
        }

        [WebInvoke(UriTemplate = "GetByMunicipio", Method = "POST")]
        public ArrayList GetByMunicipio(int IdMunicipio)
        {
            return new ArrayList(Provider.Colegios.Where(c => c.IdMunicipio == IdMunicipio).ToList());
        }
    }
}